package array;

import org.junit.Test;

/**
 *  将数组中的0移动到最后,非零数字顺序不变
 */
public class Demo1 {
    public static void main(String[] args) {
        int[] arr={30,4,0,11,0,0,4,0};
        int[] arr1={0,0,4,0,11,0,0,4,0};
        sort(arr);
        sort(arr1);
        for (int i : arr) {
            System.out.print(i+"\t");
        }
        System.out.println();
        for (int i : arr1) {
            System.out.print(i+"\t");
        }
    }

    public static void sort(int[] arr){
        int count=0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i]!=0){
                arr[count]=arr[i];
                if (count!=i){
                    arr[i]=0;
                }
                count++;
            }
        }
    }


}
